import java.io.File;
import java.io.IOException;
import java.util.Date;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;


public class Searcher {
	public static void main(String[] args) throws IOException, ParseException {
		File indexDir = new File(args[0]);
		String q = args[1];
		search(indexDir, q);
	}

	private static void search(File indexDir, String q) throws IOException, ParseException {
		Directory fsDir = FSDirectory.getDirectory(indexDir, false);
		IndexSearcher is = new IndexSearcher(fsDir);
		
		Query query = QueryParser.parse(q, "contents", new StandardAnalyzer());
		long start = new Date().getTime();
		long end = new Date().getTime();
		
		Hits hits = is.search(query);
		
		for (int i = 0; i < hits.length(); i++) {
			Document doc = hits.doc(i);
			System.out.println(doc.get("filename"));
			
		}
		
		
	}
}
